from selene.support.shared import browser,config
from selenium.webdriver import Chrome
import selenium.webdriver

if __name__ == '__main__':
    config.browser_name = 'chrome'
    # 测试地址
    config.base_url = "http://192.168.0.170:5001"
    config.timeout = 10
    config.save_screenshot_on_failure = False

    option = selenium.webdriver.ChromeOptions()
    # 禁止infobars
    option.add_argument("--diasble-infobars")
    # 禁止共享内存
    option.add_argument("--diasble-dev-shm-usage")
    # Chrome在root权限下跑
    option.add_argument("--no-sandbox")
    option.add_argument("--headless")
    # 禁止扩展
    option.add_argument("--diasble-extensions")
    # 有时候要测https协议的网站，要把https的ssl check给关了
    option.add_argument("--ignore-ssl-errors")
    option.add_argument("--ignore-certificate-errors")
    option.add_argument("--diasble-gpu")
    prefs = {'download.default_directory':'/home/seluser/Downloads/'}
    option.add_experimental_option('prefs',prefs)
    # option.add_experimental_option('w3c', False)
    # selenium3 不支持下面的内容，这是selenium4才公布的dev tools
    # option.add_experimental_option('perfLoggingPrefs', {
    #     'enableNetwork':True,
    #     'enablePage':False,
    # })
    caps = option.to_capabilities()
    caps['goog:loggingPrefs'] = {'performance':'ALL'}
    config.driver = selenium.webdriver.Remote(
        # 浏览器的主集群的地址
        command_executor='http://192.168.0.170:5001/wd/hub',
        desired_capabilities=caps,
        keep_alive=True,
        options=option)
    config.driver.set_page_load_timeout(10)

browser.open('/')
browser.driver.maximize_window()

